Skip to content

fix: preserve non-nil omitempty struct pointers - #601

Open
Boulea7 wants to merge 2 commits into
goccy:masterfrom
Boulea7:fix/omitempty-struct-pointer
Open

fix: preserve non-nil omitempty struct pointers#601
Boulea7 wants to merge 2 commits into
goccy:masterfrom
Boulea7:fix/omitempty-struct-pointer

Conversation

@Boulea7

@Boulea7 Boulea7 commented Aug 10, 2026

Copy link
Copy Markdown

Fixes #503.

Summary

The OpStructPtrHeadOmitEmpty VM path dereferenced a struct pointer and then fell through to the struct-value omit-empty path. That path could interpret a zero-valued first child field as a nil pointer and omit the entire non-nil child.

This change keeps pointer traversal and nil checks at the correct indirection depth in the VM template, then regenerates all four VM variants (vm, vm_color, vm_indent, and vm_color_indent). For direct-interface root structs, the compiler consumes exactly the pointer layer already held in the interface word, preserves additional pointer depth and recursive layouts, and bases recursion checks only on encoded fields. The regression matrix covers zero-valued first fields, nil and multi-level pointers, nested and sibling fields, pointer-valued child fields, ignored markers and back-references, and recursive roots across plain, colorized, indented, and colorized-indented output.

Testing

  • go test . -run '^TestIssue503$' -count=100 with Go 1.21.13
  • go test . -run '^TestIssue503$' -count=10 with Go 1.19.13 and 1.20.14
  • go test ./... -count=1 with Go 1.19.13, 1.20.14, and 1.21.13
  • go test -race ./... -count=1 with Go 1.21.13
  • go generate ./internal/... with no generated diff
  • golangci-lint v1.54.2 run --timeout=5m
  • go vet ./... reports exactly the same existing diagnostics as master

Change-Id: I9f2b3d140fd5e0bd3a757758a90271ddf2540068
Copilot AI lite review requested due to automatic review settings August 10, 2026 15:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Empty encode result in case of zero first byte in child struct as pointer with omitempty tag

2 participants